package util

func IndexOfStr(a []string, x string) int {
	for idx, n := range a {
		if x == n {
			return idx
		}
	}
	return -1
}

// ContainsStr 查询是否在数组中存在
func ContainsStr(a []string, x string) bool {
	for _, n := range a {
		if x == n {
			return true
		}
	}
	return false
}

func ContainInt8(a []int8, x int8) bool {
	for _, n := range a {
		if x == n {
			return true
		}
	}
	return false
}

func ContainInt(a []int, x int) bool {
	for _, n := range a {
		if x == n {
			return true
		}
	}
	return false
}

func ContainInt32(a []int32, x int32) bool {
	for _, n := range a {
		if x == n {
			return true
		}
	}
	return false
}

func ContainInt64(a []int64, x int64) bool {
	for _, n := range a {
		if x == n {
			return true
		}
	}
	return false
}

func ContainFloat64(a []float64, x float64) bool {
	for _, n := range a {
		if x == n {
			return true
		}
	}
	return false
}

func ContainFloat32(a []float32, x float32) bool {
	for _, n := range a {
		if x == n {
			return true
		}
	}
	return false
}

func DistrictParse(code string) string {
	if len(code) != 6 {
		return code
	}
	// 省级
	if code[2:] == "0000" {
		return code[:2]
	}
	// 市级
	if code[4:] == "00" {
		return code[:4]
	}
	return code
}

// IsDistrictCode 是否是区级编码
func IsDistrictCode(code string) bool {
	if len(code) != 6 {
		return false
	}
	return code[4:] != "00"
}

// ToCityCode 转换为城市编码
func ToCityCode(code string) string {
	if len(code) != 6 {
		return code
	}
	return code[:4] + "00"
}

// ToProvinceCode 转换为省级编码
func ToProvinceCode(code string) string {
	if len(code) != 6 {
		return code
	}
	return code[:2] + "0000"
}
